//
//  HomeFM.swift
//  FM
//
//  Created by x on 2017/8/30.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class HomeFM: NSObject {
    
    /// FM的id
    var id:String?
    
    /// FM的标题
    var title:String?
    
    /// FM的图标
    var cover:String? {
        didSet{
            iconImageURL = URL(string: cover!)
        }
    }
    
    /// FM的数据url地址(下载地址)
    var url: String? {
        didSet {
            fmURL = URL(string: url!)
        }
    }
    
    /// FM的作者
    var speak:String?
    
    /// 喜欢数量
    var favnum:String?
    
    /// 被收藏数量
    var viewnum:String?
    
    var background:String?
    
    /// 标记是否是老师
    var is_teacher:Bool = false
    
    /// FM播放地址
    var absolute_url:String? {
        didSet {
            fmPlayerURL = URL(string: absolute_url!);
        }
    }
    
    /// 状态码
    var status:String?
    
    /// 项目ID
    var object_id:String?
    
    /// 电台信息
    var diantai:Radio?
    
    /// 保存FM的图标的url
    var iconImageURL:URL?
    
    ///fm的下载url
    var fmURL:URL?
    
    ///FM播放地址
    var fmPlayerURL:URL?
    
    ///保存收藏数量
    var collectionNum:String?
    
    
    /// 快速返回一个数据模型数组
    ///
    /// - Parameter datas: <#datas description#>
    class func analysisData(datas:[[String:AnyObject]]) ->[HomeFM] {
        var models:[HomeFM] = [HomeFM]()
        for dic in datas {
            models.append(HomeFM(dict: dic))
        }
        
        return models
    }
    
    init(dict:[String: AnyObject]) {
        super.init()
        setValuesForKeys(dict)
    }
    override func setValue(_ value: Any?, forKey key: String) {
        //拦截KVC,给用户赋值信息(一定要super)
        super.setValue(value, forKey: key)
        if "diantai" == key {
            diantai = Radio(dic: value as! [String:AnyObject])
            return
        }
    }
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        //print("homefm===key=======\(key)")
    }
    
    /// 打印model数据模型
    override var description: String {
        let keys = ["id","title","cover","url","speak","favnum","viewnum","background","is_teacher","absolute_url","status","object_id","diantai"]
        let dic = dictionaryWithValues(forKeys: keys)
        
        return "\(dic)"
    }

    
}
